class Solution {
public:
    int subarraysDivByK(vector<int>& nums, int k) {
        unordered_map<int,int> hash;
        int count = 0, sum = 0;
        hash[0] = 1;
        for(auto x : nums)
        {
            sum += x;
            int ret = (sum % k + k) % k;
            if(hash.count(ret))
            count += hash[ret];
            hash[ret]++;
        }
        return count;
    }

